import { defineStore } from 'pinia'

/**
 * 模板列表
 * @methods setTemplatesList 设置模板数据
 */
export const gloabl = defineStore('global', {
  state: (): GlobalStatus => ({
    requestNumber:0,
    opNames:{},
    loading: false,
    error: ''
  }),
  actions: {
    startLoading({opName}:any){
        this.requestNumber++
        if (opName){
          this.opNames[opName] = true
        }
    },
    finishLoading({opName}:any){
      this.requestNumber--
      delete this.opNames[opName]

    }
  },
  getters:{
    isLoading:(state)=>{
        return state.requestNumber >0
    },
    isOpLoading: state=>(opName:string)=>{
      return state.opNames[opName]
    }
  }
})
